package com.syyo.admin.controller;

import com.syyo.admin.common.anno.SysLog;
import com.syyo.admin.domain.ResultVo;
import com.syyo.admin.utils.R;
import com.syyo.admin.domain.req.SysPostReq;
import com.syyo.admin.service.SysPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author: wang
 * @date: 2021-08-11 10:05:15
 */
@Api(tags = "系统：岗位管理")
@RestController
@RequestMapping("/sysPost")
public class SysPostController {

    @Autowired
    private SysPostService sysPostService;

     /**
      * 岗位新增
      * @param
      * @return
      */
    @SysLog("岗位新增")
    @ApiOperation("岗位新增")
    @PreAuthorize("@syyo.check('system:sysPost:add')")
    @PostMapping
    public ResultVo add(@RequestBody SysPostReq req) {
        return R.ok(sysPostService.add(req));
    }

     /**
      * 岗位删除
      * @param
      * @return
      */
    @SysLog("岗位删除")
    @ApiOperation("岗位删除")
    @PreAuthorize("@syyo.check('system:sysPost:del')")
    @DeleteMapping
    public ResultVo del(@RequestBody SysPostReq req) {
        return R.ok(sysPostService.del(req));
    }

    /**
      * 岗位编辑
      * @param req
      * @return
      */
    @SysLog("岗位编辑")
    @ApiOperation("岗位编辑")
    @PreAuthorize("@syyo.check('system:sysPost:edit')")
    @PutMapping
    public ResultVo edit(@RequestBody SysPostReq req) {
        return R.ok(sysPostService.edit(req));
    }

    /**
      * 岗位详情
      * @param
      * @return
      */
    @ApiOperation("岗位详情")
    @GetMapping("/{id}")
    public ResultVo findOne(@PathVariable("id") Integer id) {
        return R.ok(sysPostService.findOne(id));
    }

    /**
      * 岗位列表
      * @param
      * @return
      */
    @ApiOperation("岗位列表")
    @GetMapping("/list/{pageNum}/{pageSize}")
    public ResultVo findPage(@PathVariable("pageNum") Integer pageNum,
                            @PathVariable("pageSize") Integer pageSize,
                            SysPostReq req) {
        return R.ok(sysPostService.findPage(pageNum, pageSize, req));
    }

    /**
     * 岗位导出
     * @param
     * @return
     */
    @SysLog("岗位导出")
    @ApiOperation("岗位导出")
    @PreAuthorize("@syyo.check('system:sysPost:export')")
    @PostMapping("/export")
    public void findPage(HttpServletResponse response) {
        sysPostService.export(response);
    }

    /**
     * 岗位列表，全部
     * @param
     * @return
     */
    @ApiOperation("岗位列表")
    @GetMapping("/list")
    public ResultVo findAll() {
        return R.ok(sysPostService.findAll());
    }
}